#ifndef INTEROPREADER_H
#define INTEROPREADER_H

#include "transf.hxx"
#include <string>
#include <unordered_map>
#include <vector>
#pragma once
#include "common/constant.h"
#include "lists.hxx"
#include "SPAIopInputProductStructure.h"
#include "SPAIopPSImportResult.h"
#include "SPAIopInputPSMissingFileIter.h"
#include "InterOpObject.h"
#include "SPAIopPMIData.h"
#include "SPAIopMappingData.h"
#include "pmi/InterOpShapePMIInfos.h"

AMCAX_EXCHANGE_NAMESPACE_BEGIN

namespace InterOp {

class InterOpDocumentInstance;
class InterOpDocumentReference;

class Reader
{
public:
    Reader(std::string file_path);
    void ReadFromFilePath() ;
    
    void SetExchangeObjectList(std::vector<std::shared_ptr<InterOpObject>> *exchangeObjectList)
    {
        exchangeObjectList_ = exchangeObjectList;
    }

    void SetExchangeRootInstance(std::shared_ptr<InterOp::InterOpDocumentInstance> *rootDocInstance)
    {
        rootInterOpDocInstance_ = *rootDocInstance;
    }

    std::shared_ptr<InterOp::InterOpDocumentInstance> GetExchangeRootInstance()
    {
        return rootInterOpDocInstance_;
    }

    std::unordered_map<std::string, PMI::InterOpShapePMIInfos> GetPmiInfo(){
        return  oPMIInfos_;
    }

private:
    void ConvertInterOpToObject(const SPAIopInputProductStructure &productStructure, SPAIopPSImportResult& inputPSResult) ;
    
    std::shared_ptr<InterOpDocumentInstance> ParseInstanceRecursion(const SPAIopInputPSInstance& iopInputInstance, SPAIopInputPSMissingFileIter& iMissingFiles);
    void ImportPartBrep(const SPAIopInputPSReference& reference, AMCAX::TopoShape& parentShape, std::unordered_map<AMCAX::TopoShape, InterOpMaterial>& materials);

    // void TraverserPMIData(const SPAIopPMIData &pmiData,SPAIopMappingData & mappingData, bool iIsAssemblyPMI=false) ;
    
private:
    std::string filePath_;
    std::unordered_map<int ,ENTITY_LIST> referenceEntityCache;
    std::vector<std::shared_ptr<InterOpObject>> *exchangeObjectList_;

    std::shared_ptr<InterOp::InterOpDocumentInstance> rootInterOpDocInstance_ = nullptr;
    std::unordered_map<unsigned int, std::shared_ptr<InterOpDocumentReference>> docRefIdMap_;
    std::unordered_map<std::string, PMI::InterOpShapePMIInfos> oPMIInfos_;
};

}

AMCAX_EXCHANGE_NAMESPACE_END

#endif